package com.chinaoly.sdk.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;

import com.chinaoly.sdk.util.AppUtils;
import com.chinaoly.sdk.util.ToastUtils;
import com.chinaoly.sdk.util.Utils;

public abstract class BaseActivity extends AppCompatActivity implements MyBaseView {


    protected Activity mActivity;
    protected View mContentView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = this;
        initData(savedInstanceState);
        setRootLayout(bindLayout());
        initView(savedInstanceState, mContentView);
        doBusiness();

        AppUtils.registerAppStatusChangedListener(this, new Utils.OnAppStatusChangedListener() {
            @Override
            public void onForeground() {
                ToastUtils.showShort("foreground");
            }

            @Override
            public void onBackground() {
                ToastUtils.showShort("background");
            }
        });
    }


    @Override
    public void setRootLayout(int layoutId) {
        if (layoutId <= 0) {
            return;
        }

        mContentView = LayoutInflater.from(this).inflate(layoutId, null);
        setContentView(mContentView);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppUtils.unregisterAppStatusChangedListener(this);
    }
}
